<?php
/**
 * Notification util
 *
 * PHP version 5
 *
 * @category   Web
 * @package    Tourstart
 * @subpackage Util
 * @author     Alex Slubsky <aslubsky@gmail.com>
 * @license    Tourstart License http://tourstart.dk/license
 * @version    SVN: $Id: $
 *
 *
 */

/**
 * Includes
 */


/**
 * Notification util
 *
 * PHP version 5
 *
 * @category   Web
 * @package    Tourstart
 * @subpackage Search
 * @author     Alex Slubsky <aslubsky@gmail.com>
 * @license    Tourstart License http://tourstart.dk/license
 * @version    Release: $Id: $
 *
 *
 */

class DaemonSvnChecker extends DaemonAbstract
{
    public function work()
    {
        $projects = Project::getAll();
        foreach($projects as $project) {
            $this->check($project);
        }
    }
    
    protected function check(Project $project)
    {
        $comand = 'ant -file /bazalt/configs/build.xml -Dproject='.$project->name.' get-last-revision';
        exec($comand . " 2>&1", $out);
        $revision = 0;
        //$this->logger->info( implode("\n",$out) );
        foreach($out as $str) {
            if(strstr($str,'Revision:') === false) {
                continue;
            }
            $rev = explode(':',$str);
            $revision = intval(trim($rev[1]));
        }
        if($revision > 0 && $revision != $project->last_revision) {
            $project->last_revision = $revision;
            $project->save();
            
            $task = new Scheduler();
            $task->task = 'build';
            $task->project_id = $project->id;
            $task->result_path = SITE_DIR.'/../builds/'.$project->name.'/';
            $task->save();
        }
    }
}


